from rest_framework import serializers

from areas.models import Area


class AreasSerializer(serializers.ModelSerializer):
    """行政区划信息序列化器"""

    class Meta:
        model = Area
        fields = ['id', 'name']


class SubAreaSerializer(serializers.ModelSerializer):
    """子行政区划信息序列化器"""
    # 使用关联对象的序列化器，实现显示关联属性的所有信息
    subs = AreasSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
